//
//  NSString+MD5.m
//  FOMA
//
//  Created by Ma Wenqiu on 07/10/14.
//  Copyright (c) 2014 SMARTGROUP. All rights reserved.
//

#import "NSString+MD5.h"

@implementation NSString (MD5)

- (NSString *) md5HexDigest{
    
        if(self == nil || [self length] == 0)
            return nil;
        
        const char *value = [self UTF8String];
        
        unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
        CC_MD5(value, strlen(value), outputBuffer);
        
        NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
        for(NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++){
            [outputString appendFormat:@"%02x",outputBuffer[count]];
        }
        
        return outputString;
}

-(NSString *) imageType
{
    NSString * imageTypeStr = @"";

    NSMutableArray *arr = (NSMutableArray *)[self componentsSeparatedByString:@"."];
    if (arr) {
        imageTypeStr = [arr objectAtIndex:arr.count-1];
    }
    return imageTypeStr;
}
-(NSString *) imageFullName
{
    NSString * imageFullNameStr = @"";
    
    NSMutableArray *arr = (NSMutableArray *)[self componentsSeparatedByString:@"/"];
    if (arr) {
        imageFullNameStr = [arr objectAtIndex:arr.count-1];
    }
    return imageFullNameStr;
}
-(NSString *) imageShortName
{
    NSString * imageNameStr = @"";
    NSString * imageFullNameStr = @"";
    
    NSMutableArray *arr = (NSMutableArray *)[self componentsSeparatedByString:@"/"];
    if (arr) {
        imageFullNameStr = [arr objectAtIndex:arr.count-1];
        NSMutableArray *arrTemp = (NSMutableArray *)[imageFullNameStr componentsSeparatedByString:@"."];
        imageNameStr = [arrTemp objectAtIndex:0];
    }
    return imageNameStr;
}
@end
